package com.example.my_flea_street.controller;


import com.example.my_flea_street.bean.Banner;
import com.example.my_flea_street.bean.HomeHeads;
import com.example.my_flea_street.bean.ResponseModel;
import com.example.my_flea_street.service.impl.HomeServiceImpl;
import com.example.my_flea_street.util.ResponseHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/home")
public class HomeController {

    private final HomeServiceImpl homeService;

    @Autowired
    public HomeController(HomeServiceImpl homeService) {
        this.homeService = homeService;
    }

    @RequestMapping(value = "/getBanner", method = {RequestMethod.POST, RequestMethod.GET})
    public ResponseEntity<ResponseModel> getBanner() {
        List<Banner> banners =  homeService.getBanner();
        return ResponseHelper.createResponse(0, "成功",banners);
    }

    @RequestMapping(value = "/getHeads", method = {RequestMethod.POST, RequestMethod.GET})
    public ResponseEntity<ResponseModel> getHeads() {
        HomeHeads heads = new HomeHeads();
        List<List<String>> list = new ArrayList<>();
        for (int i=0;i<6;i++) {
            list.add(homeService.getHeads(i));
        }
        heads.setHeads(list);
        return ResponseHelper.createResponse(0, "成功",heads);
    }
}
